package Utilidades;

import java.io.File;
import java.io.FileOutputStream;
import java.text.Normalizer;

public class ArchivoWeb {

    public ArchivoWeb() {}
    
    public void cargarImagen(String base64Code, String path) throws Exception{
    
        byte [] imagen = Base64.decode(base64Code);

        File f = new File(path.substring(0, path.lastIndexOf(File.separatorChar)));
        f.mkdirs();        
        f = new File(path);

        FileOutputStream fos = new FileOutputStream(f);

        fos.write(imagen);

        fos.close();
    
    }
    
    public static File escribirArchivo(String base64Code, String path) throws Exception{
        
        File version = new File(path);
        if(!version.exists()){
            
            byte[] bversion = Base64.decode(base64Code);
            FileOutputStream fos = new FileOutputStream(version);
            fos.write(bversion);
            fos.close(); 
            
        }
        
        return version;
        
    }
    
    public String normalizar(String cadena){
        
        String normalizada = Normalizer.normalize(cadena, Normalizer.Form.NFD);
        normalizada = normalizada.replaceAll("[^\\p{ASCII}]", "");        
        normalizada = normalizada.replaceAll("\\s", "");    
        normalizada = normalizada.replaceAll("\\?", ""); 
        normalizada = normalizada.replaceAll("\\]\\-\\+\\^\\[\\*\\}\\{\\,\\;\\<\\>", "");
        normalizada = normalizada.replaceAll("'", "");
        normalizada = normalizada.replaceAll("\"", "");                
        return normalizada;
    }

}
